import { sumBy } from "lodash";
import { PRODUCT_STATUS_OPTIONS, PRODUCT_STATUS_VALUES, TABS } from "../constant";
import { Tag, Typography } from "antd";
import { Link } from "react-router-dom";
import styles from "./index.module.less";

const { Text } = Typography;

export const TABLE_COLUMNS = (statusLabels: any) => [
	{
		title: "商品名称",
		dataIndex: "product_name",
		width: 140,
		fixed: "left",
		ellipsis: true,
		className: styles.name,
		render: (_, record) => {
			return <Link to={`/product/createProduct?id=${record?.product_id}&isView=1`}>{record?.product_name}</Link>;
		}
	},
	{
		title: "店铺名称",
		dataIndex: "shop_name",
		width: 140,
		ellipsis: true,
		render: (_, record) => {
			return <Text ellipsis={{ tooltip: true }}>{record?.shop_info?.shop_name ?? "-"}</Text>;
		}
	},
	// {
	// 	title: "商品ID",
	// 	dataIndex: "product_id",
	// 	width: 180
	// },
	{
		title: "价格",
		dataIndex: "ad",
		width: 140,
		// render: (_, record) => `￥${record?.format_product_min_price ?? 0} / ￥${record?.format_product_max_price ?? 0}`
		render: (_, record) => `￥${record?.format_product_min_price ?? 0}`
	},
	{
		title: "累计销量",
		dataIndex: "product_sales_num",
		width: 100
	},
	{
		title: "库存总量",
		dataIndex: "stock",
		width: 100,
		render: (_, record) => sumBy(record?.sales_specs_list, i => i.stock) ?? 0
	},
	{
		title: "创建时间",
		dataIndex: "created_at",
		width: 160
	},
	{
		title: "状态",
		dataIndex: "product_status",
		width: 100,
		render: (_, record) => {
			// console.log(statusLabels, '<=========statusLabels')
			const value = record?.product_status;
			const bgColor =
				value === PRODUCT_STATUS_VALUES.sales
					? "#E5FDE9"
					: value === PRODUCT_STATUS_VALUES.sale_pending
					? "#FFF8ED"
					: value === PRODUCT_STATUS_VALUES.off_shelf
					? "#F3F4F7"
					: "";
			const color =
				value === PRODUCT_STATUS_VALUES.sales
					? "#0B801E"
					: value === PRODUCT_STATUS_VALUES.sale_pending
					? "#DE6700"
					: value === PRODUCT_STATUS_VALUES.off_shelf
					? "#7E7E7E"
					: "";
			return (
				<Tag style={{ background: bgColor, color, border: "none", marginRight: 0 }}>
					{statusLabels?.find(i => i.product_status_id == value)?.product_status_name ?? "-"}
				</Tag>
			);
		}
	}
];
